package com.tjn.date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class LocalDate_ {
    public static void main(String[] args) {
        LocalDateTime ldt = LocalDateTime.now();//可以获取当前年月日时分秒
        System.out.println(ldt);

        //DateTimeFormatter可以自定义格式
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(ldt);
        System.out.println(format);

        System.out.println("年:" + ldt.getYear());
        System.out.println("月:" + ldt.getMonth());//英文月份
        System.out.println("月:" + ldt.getMonthValue());//数字月份
        System.out.println("日:" + ldt.getDayOfMonth());
        System.out.println("时:" + ldt.getHour());
        System.out.println("分:" + ldt.getMinute());
        System.out.println("秒:" + ldt.getSecond());

        LocalDate now = LocalDate.now();//可以获取当前日期年月日
        LocalTime now1 = LocalTime.now();//可以获取当前时间时分秒
        System.out.println(now);
        System.out.println(now1);

        //提供plus和minus方法，可以对当前时间进行加减
        LocalDateTime localDateTime = ldt.plusDays(678);
        System.out.println("678天后:" + localDateTime);

        LocalDateTime localDateTime1 = ldt.minusMinutes(7658);
        System.out.println("7658分钟前:" + localDateTime1);

    }
}
